FROM openanolis/anolisos:8.8 as downloader
RUN yum install git -y
WORKDIR /root
RUN git clone --branch soc-1.0.5 --single-branch --depth 1 https://gitee.com/anolis/sysom.git

FROM node:16.20.1 as web_builder
COPY --from=downloader /root/sysom/sysom_web /root/sysom_web
RUN sed -i 's/host: "sysom_api"/host: "sysom_api_hide"/g' /root/sysom_web/src/app.jsx && \
    sed -i "s/redirect: '\/welcome'/redirect: '\/home'/g" /root/sysom_web/config/routes.js && \
    sed -i "s/redirect: '\/welcome'/redirect: '\/home'/g" /root/sysom_web/src/pages/user/Login/index.jsx
WORKDIR /root/sysom_web
RUN mv /root/sysom_web/public/resource/diagnose/v2/multichannel_openapi.json /root/sysom_web/public/resource/diagnose/v2/multichannel.json
RUN mv /root/sysom_web/public/resource/diagnose/v2/locales_openapi.json /root/sysom_web/public/resource/diagnose/v2/locales.json
RUN npm config set registry https://registry.npmmirror.com
RUN yarn config set registry https://registry.npmmirror.com
RUN yarn
RUN yarn build


FROM openanolis/anolisos:8.8 as prod

# Add epel
RUN yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
RUN bash -c "sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*"
RUN bash -c "sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*"

# Add required yum packages
RUN yum makecache
RUN yum install -y supervisor cronie net-tools
RUN systemctl enable crond
RUN yum install -y python39
RUN yum install -y nginx
RUN yum install -y redis
RUN yum install -y wget
RUN systemctl enable supervisord
RUN systemctl enable nginx

# Init sysom-diagnosis
ARG SYSOM_HOME=/usr/local/sysom
ARG SYSOM_SERVER_HOME=${SYSOM_HOME}/server

RUN mkdir /root/sysom
RUN mkdir -p /usr/local/sysom
COPY --from=downloader /root/sysom/conf /root/sysom/conf
COPY --from=downloader /root/sysom/script /root/sysom/script
COPY --from=downloader /root/sysom/deps /root/sysom/deps
COPY --from=downloader /root/sysom/environment /root/sysom/environment
COPY --from=downloader /root/sysom/sysom_server /root/sysom/sysom_server

RUN mv /root/sysom/environment/0_env/requirements-3.9.txt /root/sysom/environment/0_env/requirements.txt && \
    mv /root/sysom/script/server/sysom_api/requirements-3.9.txt /root/sysom/script/server/sysom_api/requirements.txt && \
    mv /root/sysom/script/server/sysom_cmg/requirements-3.9.txt /root/sysom/script/server/sysom_cmg/requirements.txt && \
    mv /root/sysom/script/server/sysom_diagnosis_openapi/requirements-3.9.txt /root/sysom/script/server/sysom_diagnosis_openapi/requirements.txt && \
    sed -i 's/python3/python3.9/g' /root/sysom/environment/0_env/install.sh
RUN bash -x /root/sysom/script/sysom.sh install deps 0_mysql,1_redis,2_nginx
RUN bash -x /root/sysom/script/sysom.sh install env ALL
RUN bash -x /root/sysom/script/sysom.sh install ms sysom_cmg,sysom_api,sysom_diagnosis_openapi

COPY --from=web_builder /root/sysom_web/dist /usr/local/sysom/web

RUN yum clean all

COPY --from=downloader /root/sysom/docker/sysom-init.service /usr/lib/systemd/system/sysom-init.service
RUN systemctl enable sysom-init.service

# # 环境准备
ENTRYPOINT [ "/usr/sbin/init" ]